package com.xsmart.oa.dao;

import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/29.
 */
@Component
public interface SystemParamConfigDAO {
    @Insert("insert into cfgs_sys_param(param_code,param_name,param_group_code,param_group_text,param_value,param_status)values(#{paramCode},#{paramName},#{paramGroupCode},#{paramGroupText},#{paramValue},#{paramStatus})")
    public int insertSystemParam(@Param("paramCode")String paramCode,@Param("paramName")String paramName,@Param("paramGroupCode")String paramGroupCode,@Param("paramGroupText")String paramGroupText,@Param("paramValue")String paramValue,@Param("paramStatus")Integer paramStatus);

    @Select("<script>select DISTINCT (CASE WHEN param_status = '0' THEN '不在用' WHEN param_status = '1' THEN '在用' END)param_status,param_id,param_code,param_name,param_group_code,param_group_text,param_value from cfgs_sys_param " +
            "<where> 1=1  <if test=\"paramCode!=null and paramCode!=''\"> and param_code=#{paramCode}</if>" +
            "<if test=\"paramName!=null and paramName!=''\">and param_name like concat(concat('%',#{paramName}),'%')</if></where></script>")
    List<Map<String,Object>>queryCfgsSysParam(Pagination page,@Param("paramCode")String paramCode,@Param("paramName")String paramName);


    @Update("update cfgs_sys_param set param_code=#{paramCode},param_name=#{paramName},param_group_code=#{paramGroupCode},param_group_text=#{paramGroupText},param_value=#{paramValue},param_status=#{paramStatus} where param_id=#{paramId}")
    int updateCfgsSysParam(@Param("paramCode")String paramCode,@Param("paramName")String paramName,@Param("paramGroupCode")String paramGroupCode,@Param("paramGroupText")String paramGroupText,@Param("paramValue")String paramValue,@Param("paramStatus")Integer paramStatus,@Param("paramId")Integer paramId);
}
